//
//  MineBuyCell.m
//  copyrightTrading
//
//  Created by 郭子一 on 2020/10/6.
//  Copyright © 2020 郭子一. All rights reserved.
//

#import "MineBuyCell.h"

@interface MineBuyCell ()

@property (nonatomic, strong) UIImageView *img;
@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UILabel *middleLab;
@property (nonatomic, strong) UILabel *priceLab;
@property (nonatomic, strong) UIButton *buyBtn;

@end

@implementation MineBuyCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.contentView.backgroundColor = RGB_VALUE(0xF5F5F5);
        [self setupUI];
    }
    return self;
}

- (void)setupUI
{
    self.img = [[UIImageView alloc] init];
    self.img.layer.masksToBounds = YES;
    self.img.layer.cornerRadius = 10;
    self.img.backgroundColor = UIColor.cyanColor;
    [self.contentView addSubview:self.img];
    [self.img mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.offset(0);
        make.left.offset(20);
        make.width.mas_equalTo(140);
        make.height.mas_equalTo(90);
    }];
    
    self.titleLab = [UILabel new];
    self.titleLab.text = @"汽车高清宣传片";
    self.titleLab.font = JSS_MEDIUM_FONT(17);
    [self.contentView addSubview:self.titleLab];
    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.img.mas_top);
        make.left.equalTo(self.img.mas_right).offset(13);
        make.right.offset(-20);
        make.height.mas_equalTo(24);
    }];
    
    self.middleLab = [UILabel new];
    self.middleLab.text = @"购买时间：2020-09-20\n类别：视频商务\n版权：个人";
    self.middleLab.font = JSS_MEDIUM_FONT(10);
    self.middleLab.textColor = RGB_VALUE(0x848484);
    self.middleLab.numberOfLines = 0;
    [self.contentView addSubview:self.middleLab];
    [self.middleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLab.mas_bottom).offset(1);
        make.left.equalTo(self.titleLab.mas_left);
        make.right.offset(-85);
        make.height.mas_equalTo(42);
    }];
    
    self.priceLab = [UILabel new];
    self.priceLab.text = @"39.00元";
    self.priceLab.font = JSS_MEDIUM_FONT(17);
    self.priceLab.textColor = RGB_VALUE(0x848484);
    [self.contentView addSubview:self.priceLab];
    [self.priceLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.middleLab.mas_bottom).offset(2);
        make.left.equalTo(self.titleLab.mas_left);
        make.right.offset(-95);
        make.height.mas_equalTo(24);
    }];

    NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:@"39.00元"];

    [string addAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithRed:255/255.0 green:118/255.0 blue:0/255.0 alpha:1.0]} range:NSMakeRange(0, 5)];

    [string addAttributes:@{NSForegroundColorAttributeName: [UIColor colorWithRed:132/255.0 green:132/255.0 blue:132/255.0 alpha:1.0]} range:NSMakeRange(5, 1)];

    self.priceLab.attributedText = string;
    
    self.buyBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.buyBtn setTitle:@"支付" forState:UIControlStateNormal];
    [self.buyBtn setTitleColor:RGB_VALUE(0xFFFFFF) forState:UIControlStateNormal];
    [self.buyBtn.titleLabel setFont:JSS_MEDIUM_FONT_4];
    self.buyBtn.backgroundColor = RGB_VALUE(0xFF7676);
    self.buyBtn.layer.masksToBounds = YES;
    self.buyBtn.layer.cornerRadius = 5;
    [self.buyBtn addTarget:self action:@selector(buyBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.buyBtn];
    [self.buyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.offset(-16);
        make.right.offset(-20);
        make.width.mas_equalTo(72);
        make.height.mas_equalTo(30);
    }];
    
    UIView *lineView = [UIView new];
    lineView.backgroundColor = RGB_VALUE(0xDBDBDB);
    [self.contentView addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(22);
        make.right.offset(-22);
        make.height.mas_equalTo(1);
        make.bottom.offset(0);
    }];
}

- (void)buyBtnClick:(UIButton *)sender
{
    
}

- (void)setShowBuyBtn:(BOOL)showBuyBtn
{
    _showBuyBtn = showBuyBtn;
    if (showBuyBtn) {
        self.buyBtn.hidden = NO;
    } else {
        self.buyBtn.hidden = YES;
    }
}
@end
